import { Component, OnInit } from '@angular/core';
import { BandambassadorService } from '../../service/bandambassador.service';
import { NzMessageService } from 'ng-zorro-antd';
import { CommonService } from 'src/app/service/common.service';
import { ComponentBasic } from '../../app.component';
@Component({
  selector: 'app-bandambassador',
  templateUrl: './bandambassador.component.html',
  styleUrls: ['./bandambassador.component.scss'],
  providers: [BandambassadorService, CommonService]
})
export class BandambassadorComponent extends ComponentBasic implements OnInit {
  loading = true;
  pageIndex = 1;
  pageSize = 15;
  total = 1;
  doc: any = {};
  dataSet = [];
  sdate: any;
  edate: any;
  iscontact:any;
  remarks:any;
  isVisible=false;
  isOkLoading=false;
  statuslist = [{ key: null, value: '全部' }, { key: '1', value: '已联系' }, { key: '0', value: '未联系' }];
  constructor(private bandambassadorService: BandambassadorService, private msg: NzMessageService, private commonservice: CommonService) {
    super();
    super.setLayout(true, true);
  }

  ngOnInit() {
    this.searchData();
  }
  searchData(reset: boolean = false): void {
    this.loading = true;
    this.bandambassadorService.querybypage({
      offset: this.pageIndex,
      limit: this.pageSize,
      appbegintime:this.sdate,
      appendtime:this.edate,
      iscontact:this.iscontact
    }).then((res) => {
      this.loading = false;
      this.total = res.total;
      this.dataSet = res.rows;
    });
  }


  markcontact(id):void{
    //this.doc=this.bandambassadorService.querybyid({_id:id});
    let parm={
      _id:id,
      remarks:this.doc.remarks,
      iscontact:1
    }
    this.bandambassadorService.update(parm).then((res) => {
      this.searchData();
    });

  }
  editremark(id):void{
    this.isVisible = true;
    this.bandambassadorService.querybyid({_id:id}).then((res) => {
      this.doc = res;
    });
  }

  //确定修改
  handleOk(): void {
    this.isOkLoading = true;
    let parm={
      _id:this.doc._id,
      remarks:this.doc.remarks,
      iscontact:1
    }
      this.bandambassadorService.update(parm).then((res) => {
        this.searchData();
        this.isVisible = false;
        this.doc = {};
      });
    
  }

  handleCancel(): void {
    this.isVisible = false;
    this.doc = {};
  }
}
